package com.xiaoyao.novel.pojo;

import java.sql.Timestamp;

import com.xiaoyao.novel.util.ClassUtil;
import com.xiaoyao.novel.util.DateUtil;
import com.xiaoyao.novel.util.FileUtil;
import com.xiaoyao.novel.util.HtmlStatic;

public class Chapter {
	public  String chapterPath =  FileUtil.chapterPath;
	public int cid;// id
	public int bookId = 0;// 
	public String chapterTitle = "";
	public String chapterContent = "";
	public String showContent = "";
	public Timestamp updateTime = DateUtil.getNowTime();
	public String description = "";
	public String keywords = "";
	public int clickCount = 0; // 点击

	public int nextId;
	public int prevId;

	// 以下不用保存数据库
	public String webId;// 爬虫网页 id
	public String chapterUrl; // 爬虫地址
	public String chapterTxtUrl; // 实际内容地址.SCRIPT

	public String html;
	public String nextHtml;
	public String prevHtml;

	@Override
	public String toString() {
		return "Chapter [chapterTitle=" + chapterTitle + ", cid=" + cid + "]";
	}
	public String getHtml() {
		return HtmlStatic.encodeChapter(cid);
	}
	public String getNextHtml() {
		return HtmlStatic.encodeChapter(nextId);
	}
	public String getPrevHtml() {
		return HtmlStatic.encodeChapter(prevId);
	}

	public int getCid() {
		return cid;
	}

	public void setCid(int cid) {
		this.cid = cid;
	}public String getChapterPath() {
		return chapterPath;
	}

	public int getBookId() {
		return bookId;
	}

	public void setBookId(int bookId) {
		this.bookId = bookId;
	}

	public String getChapterTitle() {
		return chapterTitle;
	}

	public void setChapterTitle(String chapterTitle) {
		this.chapterTitle = chapterTitle;
	}

	public String getChapterContent() {
		chapterContent = chapterContent.replaceAll("\\\\x.{2}", "");
		if (!chapterContent.contains("\r\n") && !chapterContent.contains("<BR/>")) {
			chapterContent = chapterContent.replaceAll("\\s\\s+", "<BR/>");
		}
		chapterContent = chapterContent.replaceAll("\r\n", "<BR/>");
		chapterContent = chapterContent.replaceFirst("(?i)www.{2,15}com", "");
		chapterContent = chapterContent.replaceFirst("<a.+?</a>", "");
		chapterContent = chapterContent.replaceAll("<script.+?</script>", "").replaceAll("<SCRIPT.+?</SCRIPT>", "");
		return chapterContent;
	}

	public void setChapterContent(String chapterContent) {
		this.chapterContent = chapterContent;
	}

	public Timestamp getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Timestamp updateTime) {
		this.updateTime = updateTime;
	}

	public String getDescription() {
		if (ClassUtil.isEmpty(description)) {
			description = chapterContent.replaceAll("<.+?>", "").replaceAll("&.{2,7};", "");
			if (description.length() > 100) {
				description = description.substring(0, 100);
			}
		}
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getKeywords() {
		if (ClassUtil.isEmpty(keywords)) {
			keywords = chapterTitle;
		}
		return keywords;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}

	public String getWebId() {
		return webId;
	}

	public void setWebId(String webId) {
		this.webId = webId;
	}

	public String getChapterUrl() {
		return chapterUrl;
	}

	public void setChapterUrl(String chapterUrl) {
		this.chapterUrl = chapterUrl;
	}

	public String getChapterTxtUrl() {
		return chapterTxtUrl;
	}

	public void setChapterTxtUrl(String chapterTxtUrl) {
		this.chapterTxtUrl = chapterTxtUrl;
	}

	public int getClickCount() {
		return clickCount;
	}

	public void setClickCount(int clickCount) {
		this.clickCount = clickCount;
	}

	public int getNextId() {
		return nextId;
	}

	public void setNextId(int nextId) {
		this.nextId = nextId;
	}

	public int getPrevId() {
		return prevId;
	}

	public void setPrevId(int prevId) {
		this.prevId = prevId;
	}
	public static final String blur1 = "<a href='http://tianfengfeiye.com'> [旷世小说网tianfengfeiye.com] </a>";
	public static final String blur2 = "<a href='http://tianfengfeiye.com'> [旷世小说网tianfengfeiye.com] </a>";
	public String getShowContent() {
		chapterContent = getChapterContent();
		int length1 = chapterContent.length() / 3; // 分三份
		int length2 = chapterContent.length() * 2 / 3; // 分三份
		showContent = chapterContent.substring(0, length1) + blur1 + chapterContent.substring(length1, length2) + blur2
				+ chapterContent.substring(length2);
		return showContent;
	}
	public void setShowContent(String showContent) {
		this.showContent = showContent;
	}

	// ////////////

}
